package container.set;

import java.util.Objects;

public class User implements Comparable<User>
{
    private int userage;
    private String username;
    
    public User (int userage, String username)
    {
        this.userage = userage;
        this.username = username;
    }
    
    
    public User ()
    {
    
    }
    
    @Override
    public String toString ()
    {
        return "User{" +
               "userage=" + userage +
               ", username='" + username + '\'' +
               '}';
    }
    
    public int getUserage ()
    {
        return userage;
    }
    
    public void setUserage (int userage)
    {
        this.userage = userage;
    }
    
    public String getUsername ()
    {
        return username;
    }
    
    public void setUsername (String username)
    {
        this.username = username;
    }
    
    @Override
    public boolean equals (Object o)
    {
        if(this == o)
        {
            return true;
        }
        if(o == null || getClass() != o.getClass())
        {
            return false;
        }
        User user = (User) o;
        return userage == user.userage && username.equals(user.username);
    }
    
    @Override
    public int hashCode ()
    {
        return Objects.hash(userage, username);
    }
    
    @Override
    public int compareTo (User o)
    {
        if(this.userage < o.getUserage())
        {
            return 1;
        }
        if(this.userage == o.getUserage())
        {
            return this.username.compareTo(o.username);
        }
        return -1;
    }
}
